import request from '@/utils/service'
import request2 from '@/utils/request2'
const userApi = {
  // Login: '/auth/login',
  Login: '/ycloud-oauth/oauth/token',
  Logout: '/auth/logout',
  YcloudLogOut: '/ycloud-oauth/logout',
  ForgePassword: '/auth/forge-password',
  Register: '/auth/register',
  twoStepCode: '/auth/2step-code',
  SendSms: '/account/sms',
  SendSmsErr: '/account/sms_err',
  // get my info
  UserInfo: '/ycloud-oauth/users/info',
  EmployeeInfo: '/ycloud-organization/employees/by-user',
  UserMenu: '/user/nav',
  loginLog: '/ycloud-organization/log/loginLog',
  findOrgTagListAll: '/ycloud-organization/orgs/findOrgTagListAll'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param params
 * @returns {*}
 */
export function login(params) {
  return request.post(userApi.Login, params, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
export function autoLogin(params) {
  return request.post('out-interface-producer-server/bureau/sso', params, {
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
export function loginLog(parameter) {
  return request2({
    url: userApi.loginLog,
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha(parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getUserInfo(params) {
  return request({
    url: userApi.UserInfo,
    method: 'get',
    params
  })
}
export function getEmployeeInfo(params) {
  return request.get(userApi.EmployeeInfo, { params })
}
export function getModifyEmployeeInfo(params) {   //修改账号从新调bg-user接口
  return request2({
    url: userApi.EmployeeInfo,
    method: 'get',
    params
  })
}
export function getCurrentUserNav() {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function logout() {
  return request({
    url: userApi.Logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function YcloudLogOut(params) {
  return request({
    url: userApi.YcloudLogOut,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    params
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step(parameter) {
  return request({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}
/**
 * @description: 获取用组织标签
 * @param {data} params 参数
 * @return {promise}
 */
export function findOrgTagListAll(params) {
  return request2({
    url: userApi.findOrgTagListAll,
    method: 'get',
    params
  })
}
